import {Component, OnInit, DoCheck} from "@angular/core";
import {LocalStorage} from "../../app.local-storage";
import {APARTMENT} from "../../service/apartment.service";
import {ROUTE} from "../../service/route.service";

@Component({
  selector: 'app-e-renting-view',
  templateUrl: './e-renting-view.component.html',
  styleUrls: ['./e-renting-view.component.scss']
})
export class ERentingViewComponent implements OnInit,DoCheck {
  ngDoCheck(): void {
  }

  projects: any = [];
  banners: any = [];

  search: any = {location: '上海市'};

  constructor(private apartment: APARTMENT,
              private localStorage: LocalStorage,private route:ROUTE) {
    this.loadProject();
    this.banners = [
      {
        img: 'assets/images/e-renting-view/banner/erenting-banner04.jpg'
      },
      {
        img: 'assets/images/e-renting-view/banner/erenting-banner02.jpg'
      },
      {
        img: 'assets/images/e-renting-view/banner/erenting-banner03.jpg'
      },
      {
        img: 'assets/images/e-renting-view/banner/erenting-banner01.jpg'
      },
      {
        img: 'assets/images/e-renting-view/banner/erenting-banner05.jpg'
      }
    ];

  }

  loadProject() {
    let reqData = {
      page: 0,
      size: 7
    };
    this.apartment.getList(reqData, (message: any) => {
      if (message.content instanceof Array && message.content.length > 0) {
        let list = [];
        for (let item of message.content) {
          let data = {
            id: item.id,
            title: item.name,
            picture: item.thumb,
            address: item.address,
            content: item.brief,
            rent: item.minPrice
          }
          list.push(data);
        }
        this.projects = list;
      }
      this.search = {location: this.projects[0].address};
    });
  }

  ngOnInit() {
  }

  mouseOver(p:any){
    if(this.search.location===p.address){
      return;
    }
    this.search={location:p.address};
  }
}
